package com.youlai.boot.stepsPlan.controller;

import com.youlai.boot.stepsPlan.service.UserStepsPlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.stepsPlan.model.form.UserStepsPlanForm;
import com.youlai.boot.stepsPlan.model.query.UserStepsPlanQuery;
import com.youlai.boot.stepsPlan.model.vo.UserStepsPlanVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 用户每日步数计划前端控制层
 *
 * @author cuisheng
 * @since 2025-03-31 22:59
 */
@Tag(name = "用户每日步数计划接口")
@RestController
@RequestMapping("/api/v1/userStepsPlans")
@RequiredArgsConstructor
public class UserStepsPlanController  {

    private final UserStepsPlanService userStepsPlanService;

    @Operation(summary = "用户每日步数计划分页列表")
    @GetMapping("/page")
    public PageResult<UserStepsPlanVO> getUserStepsPlanPage(UserStepsPlanQuery queryParams ) {
        IPage<UserStepsPlanVO> result = userStepsPlanService.getUserStepsPlanPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户每日步数计划")
    @PostMapping
    public Result<Void> saveUserStepsPlan(@RequestBody @Valid UserStepsPlanForm formData ) {
        boolean result = userStepsPlanService.saveUserStepsPlan(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户每日步数计划表单数据")
    @GetMapping("/form")
    public Result<UserStepsPlanForm> getUserStepsPlanForm(
    ) {
        UserStepsPlanForm formData = userStepsPlanService.getUserStepsPlanFormData();
        return Result.success(formData);
    }

    @Operation(summary = "修改用户每日步数计划")
    @PutMapping
    public Result<Void> updateUserStepsPlan(
            @RequestBody @Validated UserStepsPlanForm formData
    ) {
        boolean result = userStepsPlanService.updateUserStepsPlan(formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户每日步数计划")
    @DeleteMapping("/{ids}")
    public Result<Void> deleteUserStepsPlans(
        @Parameter(description = "用户每日步数计划ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = userStepsPlanService.deleteUserStepsPlans(ids);
        return Result.judge(result);
    }
}
